import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/13 15:44
 * @description 动态规划, 最长递增子序列问题
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int N = sc.nextInt();
            int[] heights = new int[N];
            int[] left = new int[N];
            Arrays.fill(left, 1);
            for (int i = 0; i < N; i++) {
                heights[i] = sc.nextInt();
            }
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < i; j++) {
                    if (heights[i] > heights[j]) {
                        left[i] = Math.max(left[i], left[j] + 1);
                    }
                }
            }
            int[] right = new int[N];
            Arrays.fill(right, 1);
            for(int i = N - 1; i >= 0; i--) {
                for(int j = N - 1; j >= i; j--) {
                    if (heights[i] > heights[j]) {
                        right[i] = Math.max(right[i], right[j] + 1);
                    }
                }
            }
            int max = 0;
            for (int i = 0; i < N; i++) {
                if (left[i] == 1 || right[i] == 1) {
                    continue;
                }
                if (left[i] + right[i] - 1 > max) {
                    max = left[i] + right[i] - 1;
                }
            }
            System.out.println(N - max);
        }
    }
}
